<?php
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . "/js/jsdate/WdatePicker.js",CClientScript::POS_END);
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . "/js/jquery.validity/jquery.validate.js",CClientScript::POS_END);
?>
<div>
    <div class="form-horizontal userform">
    <?php 
        $form=$this->beginWidget('CActiveForm', array(
            'id'=>'information-form',
            'enableAjaxValidation'=>false,
            "htmlOptions"=>array("enctype"=>"multipart/form-data"),
        ));
    ?>
    <?php echo $form->errorSummary($model); ?>
        <fieldset>
            <table class="table table-bordered">
                <tbody>
                    <tr>
                        <td>
                            <div class="control-group">
                                <label class="control-label" for="n_title">新闻标题 <span class="rcolor">*</span></label>
                                 <div class="controls">
                                    <?php
                                        echo $form->textField($model,'n_title',array('class'=>'input-large pull-left','maxlength'=>160,'name'=>'n_title'));
                                    ?>
                                    <p class="error  pull-left pl8">不能为空！</p>
                                    <p for="n_title" class="error" style=""><?=isset($model->errors['n_title'])?join('',$model->errors['n_title']):""?></p>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="n_author">作者 <span class="rcolor">*</span></label>
                                <div class="controls">
                                    <?php
                                        echo $form->textField($model,'n_author',array('class'=>'input-large pull-left','maxlength'=>160,'name'=>'n_author'));
                                    ?>
                                    <p class="error  pull-left pl8">不能为空！</p>
                                    <p for="n_author" class="error" style=""><?=isset($model->errors['n_author'])?join('',$model->errors['n_author']):""?></p>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="n_publishtime">发布时间 <span class="rcolor">*</span></label>
                                <div class="controls">
                                    <?php
                                        echo $form->textField($model,'n_publishtime',array('class'=>'input-large pull-left','maxlength'=>160,'name'=>'n_publishtime','onclick'=>"WdatePicker({dateFmt:'yyyy/MM/dd HH:mm:ss'})"));
                                    ?>
                                    <p class="error  pull-left pl8">不能为空！</p>
                                    <p for="n_publishtime" class="error" style=""><?=isset($model->errors['n_publishtime'])?join('',$model->errors['n_publishtime']):""?></p>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="i_title">新闻内容 <span class="rcolor">*</span></label>
                                <div class="controls">
                                   <?php $this->widget('ext.ckeditor.CKEditorWidget',array(
								  "model"=>$model,                 # Data-Model
								  "attribute"=>'n_content',          # Attribute in the Data-Model
								  "defaultValue"=>$model->n_content,     # Optional

								  # Additional Parameter (Check http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html)
								  "config" => array(
									  "height"=>"600px",
									  "width"=>"1002px",
									  "toolbar"=>"Full",
									  ),

								  #Optional address settings if you did not copy ckeditor on application root
								  "ckEditor"=>Yii::app()->basePath."/../ckeditor/ckeditor.php",
																  # Path to ckeditor.php
								  "ckBasePath"=>Yii::app()->baseUrl."/ckeditor/",
																  # Realtive Path to the Editor (from Web-Root)
								  ) ); ?>
                                    <p class="error  pull-left pl8">不能为空！</p>
                                    <p for="n_content" class="error" style=""><?=isset($model->errors['n_content'])?join('',$model->errors['n_content']):""?></p>
                                </div>
                            </div>
                            
                            <div class="form-actions">
                                <button type="submit" class="btn btn-primary" name="addsubmit" value="add"  ><?=!$model->isNewRecord?"修改":"添加"?></button> &nbsp;
                                <?php
                                    if(isset($_GET['return'])&&$_GET['return']=='index'){
                                        $url = Yii::app()->createUrl("admin/product/index",array("id"=>$model->p_id));
                                    }else{
                                        $url = isset($_COOKIE['ggnewslistreturnurl'])?$_COOKIE['ggnewslistreturnurl']:Yii::app()->createUrl("admin/product/index");
                                    }
                                ?>
                                <a href="<?=$url?>" class="btn btn-primary">返回</a>
                            </div>
                        </td>
                    </tr>
                </tbody>
            </table>
        </fieldset>
        <?php $this->endWidget(); ?>
    </div>
</div>
<script>
    $(document).ready(function(){
	$("#information-form").validate({
            autoCreateRanges:true	,
            errorClass: "error",
            errorElement: "p",
            rules: {
                n_title: {
                    required: true,
                },
                n_author: {
                    required: true,
                },
                n_publishtime: {
                    required: true,
                },
                n_content: {
                    required: true,
                },
            },
            
            messages: {
                n_title:{
                    required: '请输入标题',
                },
                n_author:{
                    required: '请输入作者名字',
                },
                n_publishtime:{
                    required: '请选择发布时间',
                },
                n_content:{
                    required: '请填写新闻内容',
                },
            },
        });
    })
</script> 

